﻿let SimpleFor modifier state init =
    let rec for_tail current state =
        let ``done``, current, state = modifier current state
        if ``done`` then
            state
        else
            for_tail current state
    
    for_tail init state

let For cond modifier state init =
    let rec for_tail current state =
        if cond current then
            let current, state, result = modifier current state
            for_tail current state
        else
            state
    
    for_tail init state